__author__ = 'zhenjiao.su'
# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from Confing import confing
from Saveorder import saveorder
from Payserver import payserver
from Shouye import shouye
from List import search
from Detail import detail
from Other import *
alw=webdriver.Remote(command_executor="http://192.168.168.33:4444/wd/hub",desired_capabilities=DesiredCapabilities.CHROME)
alw.get("http://fh.dujia.qunar.com/?tf=package")
alw.maximize_window()
shouyes=shouye(alw)
if shouyes.shouyeexit()==True:
    print(u"进入首页成功")
    shouyes.b2ccitypeople()
    shouyes.b2cclick()
else:
    print(u"进入首页失败")
    raise SystemError
searchs=search(alw)
handl1=alw.current_window_handle
if searchs.listpageexit()==True:
    if searchs.searchloadingexit()==False:
        if searchs.searchexit()==True:
            print(u"存在搜索结果")
            searchs.searchresults()
            searchhotelname=searchs.gohotel
            searchpay=searchs.sumprice
            searchs.searchclick()
        else:
            print(u"无搜索结果")
            raise SystemError
    else:
        print(u"搜索页异常")
        raise SystemError
else:
    print(u"进入搜索页失败")
    raise SystemError
handls=alw.window_handles
alw.close()
for handl2 in handls:
    if handl2 !=handl1:
        alw.switch_to_window(handl2)
details=detail(alw)
if details.overexit("detailpageover")==True:
    print(u"detail售卖完")
    raise SystemError
if details.detailpageexit()==False:
    print(u"进入detail页失败")
    raise SystemError
else:
    print(u"进入detail成功")
sleep(10)
if details.overexit("flightexit")==True or details.overexit("hotelexit")==True or details.overexit("detailpageover")==True:
    print(u"实时接口返回卖完")
    raise SystemError
details.detailattribute()
details.detailroomsearch()
detailroomname=details.roomname
detailsumpay=details.detailsumpre
detailhotelname=details.detailhotelname
details.detailclick()
if details.detailloadexit()==False:
    print(u"detail提交失败")
    raise SystemError
elif details.detailloadexit() =="warning":
    print(u"提交异常")
    raise SystemError
if details.overexit("detailpageover")==True:
    print(u"detail提交失败，产品卖完")
    raise SystemError
confings=confing(alw)
if confings.confingexit()==True:
    confings.peopletrval()
    confings.messagepeople()
    confings.messagesubmit()
    if confings.confingloading(timeout=50)==True:
        pass
    else:
        print(u"进入saveovder失败")
        raise SystemError
else:
    print(u"进入confirm页失败")
    raise SystemError
saveorders=saveorder(alw)
hand4=alw.current_window_handle
if saveorders.saveorderexit()==True:
    saveorders.saveordersults()
    print(saveorders.savepayorder)
    saveorders.saveorderpayclick()
    while True:
        if saveorders.saveorderloading()==False:
            if saveorders.saveorderstate()==True:
                print(u"已跳转至支付中心")
                break
            elif saveorders.savepaychangeexit()==True:
                saveorders.savepaychange()
            elif saveorders.saveoverexit()==True:
                print(u"产品卖完")
                raise SystemError
            else:
                raise SystemError
hanls=alw.window_handles
alw.close()
for hand5 in hanls:
    if hand5 != hand4:
        alw.switch_to_window(hand5)
payservers=payserver(alw)
if payservers.payserverexit()==True:
    print(u"进入支付中心成功")
    payservers.payserverresults()
    print(payservers.payhotelname)
    print(payservers.paymomey)
    print(payservers.messagepeoples)
else:
    print(u"进入支付中心失败")



